#!/usr/bin/env python

import os.path
import os

def find_exec (filename):
    path = os.getenv ("PATH")
    if path is None:
        return None
    
    path = path.split (os.pathsep)
    for dir in path:
        abs_filename = os.path.join (dir, filename)
        if os.path.exists (abs_filename):
            return abs_filename

    return None

if __name__ == '__main__':
    import sys
    if len (sys.argv) != 2:
        print >> sys.stderr, "Usage: which <program name>"
        sys.exit(1)
    print find_exec (sys.argv[1])
